<template>
  <div class="marketAside">
    <div class="container">
      <ul class="navigator"
          ref="ul">
        <li @click="show('猜你喜欢')"
            class="isActive">猜你喜欢</li>
        <li @click="show('生活用品')">生活用品</li>
        <li @click="show('学习用品')">学习用品</li>
        <li @click="show('数码产品')">数码产品</li>
        <li @click="show('体育产品')">体育产品</li>
        <li @click="show('其他')">其他</li>
      </ul>
    </div>
    <div class="aside">
      <ul class="asideNav"
          ref="asideUl">
        <li @click="show2('猜你喜欢')"
            class="isActive">猜你喜欢</li>
        <li @click="show2('生活用品')">生活用品</li>
        <li @click="show2('学习用品')">学习用品</li>
        <li @click="show2('数码产品')">数码产品</li>
        <li @click="show2('体育产品')">体育产品</li>
        <li @click="show2('其他')">其他</li>
        <li @click="returnTop"><i class="el-icon-arrow-up"></i><br>顶部</li>
      </ul>
    </div>
    <market-recommend :isShow="isShow"></market-recommend>
  </div>
</template>

<script>
import MarketRecommend from "@/components/common/MarketRecommend"
export default {
  components: {
    MarketRecommend
  },
  data () {
    return {
      isShow: "猜你喜欢"
    };
  },
  methods: {
    show (id) {
      this.isShow = id;
      for (let item of this.$refs.ul.children) {
        if (item.innerText == id) {
          item.className = "isActive";
        } else {
          item.className = "";
        }
      }
      for (let item of this.$refs.asideUl.children) {
        if (item.innerText == id) {
          item.className = "isActive";
        } else {
          item.className = "";
        }
      }
    },
    show2 (id) {
      this.isShow = id;
      for (let item of this.$refs.ul.children) {
        if (item.innerText == id) {
          item.className = "isActive";
        } else {
          item.className = "";
        }
      }
      for (let item of this.$refs.asideUl.children) {
        if (item.innerText == id) {
          item.className = "isActive";
        } else {
          item.className = "";
        }
      }
      if (document.documentElement.scrollTop >= 600) {
        let timer = setInterval(() => {
          if (document.documentElement.scrollTop < 750) {
            document.documentElement.scrollTop = 650;
            clearInterval(timer);
            timer = null;
            this.$emit("wheel");
          }
          this.$emit("wheel");
          document.documentElement.scrollTop -= 100;
        }, 20)
      }
    },
    returnTop () {
      let timer = setInterval(() => {
        if (document.documentElement.scrollTop < 100) {
          document.documentElement.scrollTop = 0;
          clearInterval(timer);
          timer = null;
          this.$emit("wheel");
        }
        this.$emit("wheel");
        document.documentElement.scrollTop -= 100;
      }, 20)
    }
  }
}
</script>

<style lang="less" scoped>
.marketAside {
  width: 1050px;
  margin: 30px auto 5px;
  position: relative;

  .navigator {
    width: 1050px;
    height: 50px;
    background-color: #dcdfe6;
    display: flex;

    li {
      width: 175px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      cursor: pointer;
    }
    li:hover {
      color: #f10;
      font-weight: bold;
    }
  }
  .aside {
    position: absolute;
    width: 70px;
    height: 490px;
    background-color: #fff;
    right: -150px;

    li {
      width: 70px;
      height: 70px;
      text-align: center;
      box-sizing: border-box;
      padding: 12px;
      cursor: pointer;
    }
  }
  .isActive {
    color: #f10;
    border-bottom: 1px solid #f10;
    box-sizing: border-box;
    font-weight: bold;
  }
  .isFixed {
    position: fixed;
    right: 15px;
    top: 115px;
  }
}
</style>